import { ParamsConst } from "../../common/global/ParamsConst";
import { ProxyType } from "../../common/global/ProxyType";
import { GTextFormat } from "../../common/GTextFormat";
import { FontUtil } from "../../common/font/FontUtil";
import { FilterConst } from "../../component/gconst/FilterConst";
import { HTMLUtil } from "../../../com/gengine/utils/HTMLUtil";
import { LayerManager } from "./LayerManager";
import { TweenMax } from "../../../com/greensock/TweenMax";
import { Quint } from "../../../com/greensock/easing/Quint";
import { Global } from "../../../com/gengine/global/Global";
type int = number;
//class MsgTaskShowImpl
    
    export  class MsgTaskShowImpl
    {
        constructor()
        {
            
            this._ary = [];
            this._bmp = new Object /* flash.display.Bitmap */();
            this._matrix = new Object /* flash.geom.Matrix */(1, 0, 0, 1, 10, 10);
            return;
        }

        public showTarget(arg1: string, arg2: int=5, arg3: Boolean=false): void
        {
            var loc1=flash.utils.getTimer();
            if (arg3 == true || loc1 - this._lastShowTime > this.LimitShowTime + 970 && this._ary.length == 0) 
            {
                this._lastShowTime = loc1;
            }
            else 
            {
                this._ary.push(new Msg(arg1, arg2));
                return;
            }
            this.showMsg(arg1, arg2);
            flash.utils.setTimeout(this.showNext, this.LimitShowTime + 1000);
            return;
        }

        /* internal  */showNext(): void
        {
            var loc1=null;
            if (this._ary.length > 0) 
            {
                loc1 = this._ary.shift();
                this.showTarget(loc1.str, loc1.daily, true);
            }
            return;
        }

        /* internal  */showMsg(arg1: string, arg2: int=5): void
        {
            this.dispose();
            this._str = arg1;
            this._daily = arg2;
            if (!this._wordTxt) 
            {
                this._wordTxt = new Object /* flash.text.TextField */();
                this._wordTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
                if (ParamsConst.instance.proxyType != ProxyType.TW) 
                {
                    this._wordTxt.defaultTextFormat = new GTextFormat(FontUtil.xingkaiName, 32, 16777215, null, null, null, null, flash.text.TextFormatAlign.LEFT);
                }
                else 
                {
                    this._wordTxt.defaultTextFormat = new GTextFormat(FontUtil.songtiName, 32, 16777215, null, null, null, null, flash.text.TextFormatAlign.LEFT);
                }
                this._wordTxt.filters = [FilterConst.taskShowTargetFilter];
                this._wordTxt.selectable = false;
                this._wordTxt.mouseEnabled = false;
                this._wordTxt.height = 100;
            }
            this._wordTxt.htmlText = HTMLUtil.addColor(this._str, "#ffffff");
            this._wordTxt.alpha = 1;
            if (this._bmpd) 
            {
                this._bmpd.dispose();
                this._bmpd = null;
            }
            this._bmpd = new Object /* flash.display.BitmapData */(this._wordTxt.textWidth + 20, 100, true, 0);
            this._bmpd.draw(this._wordTxt, this._matrix);
            this._bmp.bitmapData = this._bmpd;
            if (this._bmp.parent == null) 
            {
                LayerManager.topLayer.addChild(this._bmp);
            }
            this._tweenIn = TweenMax.to(this._bmp, 0.5, {"alpha": 1, "ease": Quint.easeIn, "onComplete": this.onTweenInEnd});
            this.stageResize();
            return;
        }

        /* internal  */onTweenInEnd(): void
        {
            if (this._daily > 0) 
            {
                this._timerKey = flash.utils.setTimeout(this.onTimerEnd, this._daily * 1000);
            }
            return;
        }

        /* internal  */onTimerEnd(): void
        {
            this.hide();
            return;
        }

        public stageResize(): void
        {
            if (this._bmp && this._bmp.parent) 
            {
                this._bmp.x = (Global.stage.stageWidth - this._wordTxt.textWidth) / 2;
                this._bmp.y = Global.stage.stageHeight / 2 + (Global.stage.stageHeight / 2 - this._wordTxt.textHeight) / 2 + this._wordTxt.textHeight;
            }
            return;
        }

        public hide(): void
        {
            if (this._bmp && this._bmp.parent) 
            {
                if (this._tweenIn && this._tweenIn.active) 
                {
                    this._tweenIn.kill();
                }
                flash.utils.clearTimeout(this._timerKey);
                this._tweenOut = TweenMax.to(this._bmp, 1, {"alpha": 0, "ease": Quint.easeOut, "onComplete": this.onTweenOutEnd});
            }
            else 
            {
                this.dispose();
            }
            return;
        }

        /* internal  */onTweenOutEnd(): void
        {
            this.dispose();
            return;
        }

        public dispose(): void
        {
            if (this._tweenIn && this._tweenIn.active) 
            {
                this._tweenIn.kill();
            }
            if (this._tweenOut && this._tweenOut.active) 
            {
                this._tweenOut.kill();
            }
            flash.utils.clearTimeout(this._timerKey);
            if (this._wordTxt) 
            {
                this._wordTxt.text = "";
            }
            if (this._bmp.parent) 
            {
                this._bmp.parent.removeChild(this._bmp);
            }
            this._str = null;
            this._daily = 0;
            return;
        }

        /* internal */ /* const */LimitShowTime: int=10;

        /* internal */ /* var */_str: string;

        /* internal */ /* var */_daily: int;

        /* internal */ /* var */_wordTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_bmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpd: Object /* flash.display.BitmapData */;

        /* internal */ /* var */_tweenIn: TweenMax;

        /* internal */ /* var */_timerKey: uint;

        /* internal */ /* var */_tweenOut: TweenMax;

        /* internal */ /* var */_matrix: Object /* flash.geom.Matrix */;

        /* internal */ /* var */_ary: Array<any>;

        /* internal */ /* var */_lastShowTime: int=0;
    }
}


class Msg extends Object
{
    public Msg(arg1: string, arg2: int)
    {
        super();
        this.str = arg1;
        this.daily = arg2;
        return;
    }

    public /* var */str: string;

    public /* var */daily: int;
